<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="app-articles" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			prop: "images",
			label: "图片",
			component: { name: "cl-upload", props: { multiple: true } },
			required: true
		},
		{
			prop: "content",
			label: "内容",
			component: {
				name: "el-input",
				props: {
					type: "textarea",
					rows: 10
				}
			},
			required: true
		},
		{ prop: "circleId", label: "圈子id", required: true, component: { name: "el-input" } },
		{ prop: "tagIds", label: "tagIds", required: true, component: { name: "el-input" } },
		{ prop: "userId", label: "用户id", required: true, component: { name: "el-input" } },
		{ prop: "status", label: "状态", component: { name: "cl-switch" }, required: true }
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ prop: "id", label: "ID" },
		{ prop: "images", label: "图片", component: { name: "cl-image", props: { size: 60 } } },
		{
			prop: "content",
			label: "内容",
			component: { name: "cl-editor-preview", props: { name: "wang" } }
		},
		{
			prop: "content",
			label: "内容",
			component: { name: "cl-editor-preview", props: { name: "wang" } }
		},
		{ prop: "circleId", label: "圈子id" },
		{ prop: "tagIds", label: "tagIds" },
		{ prop: "userId", label: "用户id" },
		{ prop: "status", label: "状态", component: { name: "cl-switch" } },
		{ prop: "createTime", label: "创建时间", sortable: "desc", width: 160 },
		{ prop: "updateTime", label: "更新时间", sortable: "custom", width: 160 },
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.app.articles
	},
	(app) => {
		app.refresh();
	}
);
</script>
